# coding: utf8
# try something like
from makan import *
def call():
    session.forget()
    return service()
#####################################################################
def index(): 
    return dict(message="hello from categories.py")
    
def add():
    form = SQLFORM(db.categories)
    if form.accepts(request.vars, session):
        return T("done")
    else:
        return dict(form = form)

def update():
    if request.post_vars:
            db(db.categories.id == request.args[0]).update(
            name = request.post_vars.name)
            return T("done")
   
    else:
        cat = db.categories[request.args[0]]
        if not cat: return "category not found!"
        return dict(cat = cat)

def read():
    cat = db(db.categories.name == request.args[0]).select()
    if not cat: return "category not found"
    return dict(cat = cat)

def delete():
    db(db.categories.name == request.args[0]).delete()
    return T("done")

def list():
    cats = db().select(db.categories.ALL)
    return dict(cats = cats)
#######################################################################

@service.xmlrpc
def xGetCategories():
    cats = db(db.categories).select().as_dict()
    return cats






























